//
//  DemoCacheManager.m
//  RunloopTableViewDemo
//
//  Created by Jack on 2021/6/30.
//

#import "DemoCacheManager.h"

@implementation DemoCacheManager{
    NSMutableDictionary *_dict;
}

+ (instancetype)sharedManager{
    static DemoCacheManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[DemoCacheManager alloc] init];
    });
    return manager;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        _dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    }
    return self;
}

#pragma mark - Public
- (void)cacheResultWithKey:(NSString *)key{
    if (key && [key isKindOfClass:[NSString class]] && key.length > 0) {
        [_dict setObject:@"1" forKey:key];
    }
}

- (BOOL)isCachedWithKey:(NSString *)key{
    if (key && [key isKindOfClass:[NSString class]] && key.length > 0) {
        if ([_dict[key] isEqualToString:@"1"]) {
            return YES;
        }
    }
    return NO;
}
@end
